package org.mms.controller;

import org.mms.pojo.dto.DepartmentDto;
import org.mms.pojo.request.DepartmentRequest;
import org.mms.pojo.util.ResponseMessage;
import org.mms.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/departments")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @GetMapping
    public ResponseMessage<List<DepartmentDto>> list() {
        return ResponseMessage.success(departmentService.list());
    }

    @GetMapping("/{id}")
    public ResponseMessage<DepartmentDto> getById(@PathVariable Long id) {
        return ResponseMessage.success(departmentService.getById(id));
    }

    @PostMapping
    public ResponseMessage create(@RequestBody DepartmentRequest request) {
        departmentService.create(request);
        return ResponseMessage.success(null);
    }

    @PutMapping
    public ResponseMessage update(@RequestBody DepartmentRequest request) {
        departmentService.update(request);
        return ResponseMessage.success(null);
    }

    @DeleteMapping("/{id}")
    public ResponseMessage delete(@PathVariable Long id) {
        departmentService.delete(id);
        return ResponseMessage.success(null);
    }
}